package cn.itsource.pethome.base.controller;

import cn.itsource.pethome.base.domain.dto.VerifyDto;
import cn.itsource.pethome.base.service.IImageVerifyCodeService;
import cn.itsource.pethome.util.AjaxResult;
import cn.itsource.pethome.util.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/VerifyCode")
public class ImageVerifyCodeController {
    @Autowired
    private IImageVerifyCodeService iImageVerifyCodeService;
    @GetMapping("/image/{key}")
    public AjaxResult imageVerifyCode(@PathVariable("key") String key){
        try {
            String key1 =  iImageVerifyCodeService.imageVerifyCode(key);
            return AjaxResult.me().setData(key1);
        }catch (BusinessException e){
            return AjaxResult.error().setMsg(e.getLocalizedMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody VerifyDto verifyDto){
        try {
            iImageVerifyCodeService.sendSmsCode(verifyDto);
            return AjaxResult.me();
        }catch (BusinessException e){
            return AjaxResult.error().setMsg(e.getLocalizedMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
